include('shared.lua')

//thanks to brwarner for this
function ShowIrisCompMenu(um)
	local info = string.Explode(";", um:ReadString())
	local panel = vgui.Create("DFrame")
	panel:SetDeleteOnClose()
	panel:ShowCloseButton(false)
	panel:SetTitle("Set Iris Settings")
	panel:SetSize(230, 165)
	panel:SetPos((ScrW()/2 - 350) / 2, ScrH()/2 - 75)
	panel:MakePopup()
	
	local code = vgui.Create( "DTextEntry", panel)
	code:SetText(info[1])
	code:SetPos( 15, 40)
	code:SetSize(200, 20)	
	code:SetTooltip("Type the iris code(s) you want here.  For more than one, seperate with commas.")
	
	local closetime = vgui.Create("DTextEntry", panel)
	closetime:SetText(info[2])
	closetime:SetPos(15, 70)
	closetime:SetSize(200,20)
	closetime:SetTooltip("The time in seconds the iris will stay open after a correct code is sent.  Set to 0 to stay open forever.")

	local button = vgui.Create("DButton", panel)
	button:SetText("Save Settings")
	button:SetPos(20, 125)
	button:SetSize(80, 25)
	
	local ToggleIris = vgui.Create("DButton", panel)
	ToggleIris:SetText("Toggle Iris")
	ToggleIris:SetPos(120,125)
	ToggleIris:SetSize(85,25)
	
	local autoclose = vgui.Create("DCheckBoxLabel", panel)
	autoclose:SetText("Auto-close?")
	autoclose:SizeToContents()
	autoclose:SetPos(20, 100)
	autoclose:SetTooltip("If checked, the iris will close as soon as an incoming connection is established.")
	autoclose:SetValue(util.tobool(info[3]))
	
	local autoopen = vgui.Create("DCheckBoxLabel", panel)
	autoopen:SetText("Don't Auto-open?")
	autoopen:SizeToContents()
	autoopen:SetPos(115, 100)
	autoopen:SetValue(util.tobool(info[4]))
	autoopen:SetTooltip("If checked, the iris will not open until the wire input tells it to.")
	
	function button:DoClick()
		LocalPlayer():ConCommand("changeirissettings " .. code:GetValue() .. " " .. closetime:GetValue() .. " " .. tostring(autoclose:GetChecked()) .. " " .. tostring(autoopen:GetChecked()) .. "\n")
		LocalPlayer().IrisCompEnt = nil
		panel:Remove()
	end
	
	function ToggleIris:DoClick()
		LocalPlayer():ConCommand("togiris")
	end
end

usermessage.Hook("sic_openpanel", ShowIrisCompMenu)